﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace MvcEngine.Core.Extensions
{
    public static class CollectionExtensions
    {
        public static string ConvertToString(this IEnumerable<string> collection)
        {
            if (collection == null || collection.Count() == 0)
                return string.Empty;

            StringBuilder builder = new StringBuilder();

            foreach (var item in collection)
            {
                builder.Append(item);
                builder.Append(", ");
            }
            return builder.Remove(builder.Length - 2, 2).ToString();
        }

        //public static IEnumerable<TResult> Convert<T, TResult>(this IEnumerable collection, Func<T, TResult> action)
        //{
        //    return action(

        //    return null;
        //}


        public static T GetValue<T>(this IDictionary<string, object> dictionary, string key)
        {
            if (!dictionary.ContainsKey(key)) 
            {
                return default(T);
            }
            return (T)dictionary[key];
        }

        public static string GetString(this IDictionary<string, object> dictionary, string key)
        {
            if (!dictionary.ContainsKey(key))
            {
                return string.Empty;
            }
            return dictionary[key].ToString();
        }
    }
}
